package selef.xiafan.dao;

import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import selef.xiafan.entity.system.Stock;

import java.util.List;

public interface StockDao extends JpaRepository<Stock, String> {

    @Query(value = "SELECT COUNT(*) FROM t_stock", nativeQuery = true)
    Long countAll();

    @Query(value = "SELECT * FROM t_stock LIMIT :page,:size", nativeQuery = true)
    List<Stock> findAllNoQuery(@Param("page") Integer page, @Param("size") Integer size);

    Stock findByStockId(String stockId);

    void deleteByStockId(String stockId);

    List<Stock> findAllByEnable(boolean whichTrue);

    @Query(value = "SELECT * FROM t_stock WHERE name LIKE CONCAT('%',:nameForQuery,'%') LIMIT :page,:size ",nativeQuery = true)
    List<Stock> findAllByQuery(@Param("page") Integer page, @Param("size") Integer size, @Param("name") String nameForQuery);

    @Query(value = "SELECT COUNT(*) FROM t_stock WHERE name LIKE CONCAT('%',:nameForQuery,'%')", nativeQuery = true)
    Long countAllByQuery(@Param("name")String nameForQuery);
}
